package org.yelongframework.excel.data.fill.sheet.mode.forcopy.down;

import org.yelongframework.excel.data.fill.sheet.SheetDataFillException;
import org.yelongframework.excel.data.fill.sheet.SheetDataFillMode;
import org.yelongframework.excel.data.fill.sheet.mode.forcopy.ForCopySheetDataFillScheme;
import org.yelongframework.lang.Nullable;

/**
 * 向下循环复制工作表数据填充属性
 * 
 * @since 1.0.0
 */
public class DownForCopySheetDataFillScheme extends ForCopySheetDataFillScheme {

	/** 起始行索引 */
	private int beginRowIndex;

	/** 起始列索引 */
	private int beginColumnIndex;

	/** 结束列索引 */
	private int endColumnIndex;

	/** 循环次数 */
	private int forCount;

	/** 数据提供者 */
	private DownForCopySheetDataFillDataSupplier dataSupplier;

	/** 每页最大循环行数 */
	@Nullable
	private Integer pageMaxForCount = null;

	// ==================================================构造器==================================================

	public DownForCopySheetDataFillScheme() {
		super(SheetDataFillMode.FORCOPY_DOWN);
	}

	/**
	 * @param beginRowIndex    起始行索引
	 * @param beginColumnIndex 起始列索引
	 * @param endColumnIndex   结束列索引
	 * @param forCount         循环次数
	 * @param dataSupplier     数据提供者
	 */
	public DownForCopySheetDataFillScheme(int beginRowIndex, int beginColumnIndex, int endColumnIndex, int forCount,
			DownForCopySheetDataFillDataSupplier dataSupplier) {
		this();
		this.beginRowIndex = beginRowIndex;
		this.beginColumnIndex = beginColumnIndex;
		this.endColumnIndex = endColumnIndex;
		this.forCount = forCount;
		this.dataSupplier = dataSupplier;
	}

	// ==================================================获取/设置==================================================

	/**
	 * @return 起始行索引
	 */
	public int getBeginRowIndex() {
		return beginRowIndex;
	}

	/**
	 * @param beginRowIndex 起始行索引
	 */
	public DownForCopySheetDataFillScheme setBeginRowIndex(int beginRowIndex) {
		this.beginRowIndex = beginRowIndex;
		return this;
	}

	/**
	 * @return 起始列索引
	 */
	public int getBeginColumnIndex() {
		return beginColumnIndex;
	}

	/**
	 * @param beginColumnIndex 起始列索引
	 */
	public DownForCopySheetDataFillScheme setBeginColumnIndex(int beginColumnIndex) {
		this.beginColumnIndex = beginColumnIndex;
		return this;
	}

	/**
	 * @return 结束列索引
	 */
	public int getEndColumnIndex() {
		return endColumnIndex;
	}

	/**
	 * @param endColumnIndex 结束列索引
	 */
	public DownForCopySheetDataFillScheme setEndColumnIndex(int endColumnIndex) {
		this.endColumnIndex = endColumnIndex;
		return this;
	}

	/**
	 * @return 循环次数
	 */
	public int getForCount() {
		return forCount;
	}

	/**
	 * @param forCount 循环次数
	 */
	public DownForCopySheetDataFillScheme setForCount(int forCount) {
		this.forCount = forCount;
		return this;
	}

	/**
	 * @return 数据提供者
	 */
	public DownForCopySheetDataFillDataSupplier getDataSupplier() {
		return dataSupplier;
	}

	/**
	 * @param dataSupplier 数据提供者
	 */
	public DownForCopySheetDataFillScheme setDataSupplier(DownForCopySheetDataFillDataSupplier dataSupplier) {
		this.dataSupplier = dataSupplier;
		return this;
	}

	/**
	 * @return 每页最大循环行数
	 */
	public Integer getPageMaxForCount() {
		return pageMaxForCount;
	}

	/**
	 * @param pageMaxForCount 每页最大循环行数
	 */
	public DownForCopySheetDataFillScheme setPageMaxForCount(@Nullable Integer pageMaxForCount) {
		this.pageMaxForCount = pageMaxForCount;
		return this;
	}

	// ==================================================验证属性==================================================

	@Override
	public void check() throws SheetDataFillException {
		if (beginRowIndex < 0) {
			throw new SheetDataFillException("beginRowIndex不能小于0");
		}
		if (beginColumnIndex < 0) {
			throw new SheetDataFillException("beginColumnIndex不能小于0");
		}
		if (endColumnIndex < 0) {
			throw new SheetDataFillException("endColumnIndex不能小于0");
		}
		if (forCount < 0) {
			throw new SheetDataFillException("forCount不能小于0");
		}
		if (null == dataSupplier) {
			throw new SheetDataFillException("dataSupplier不能为空");
		}
	}

}
